package com.example.mydemo.cate.controller;

import com.auth0.jwt.interfaces.DecodedJWT;
import com.example.mydemo.cate.service.ICateService;
import com.example.mydemo.config.JWTUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/cate")
public class CateController {

    @Autowired
    private ICateService cateService;

    @GetMapping("/idName")
    public Map<Integer, String> idName() {
        Map<String, String> payload = new HashMap<>();
        payload.put("id", "1");
        payload.put("name", "zhang");
        // 生成jwt令牌
        String token = JWTUtils.getToken(payload);

        Map<Integer, String> res = new HashMap<>();
        res = cateService.idName();
        res.put(4, token);

        DecodedJWT decodedJWT = JWTUtils.getTokenInfo(token);
        String id = decodedJWT.getClaim("id").asString();
        System.out.println(id);
        return res;
    }
}
